/**
 ****************************************************************************************
 *
 * @file central.h
 *
 * @brief Header file - Letstrong Rope Profile Sensor.
 *
 * Copyright (C) Letstrong 2021-2022
 *
 *
 ****************************************************************************************
 */

#ifndef _CENTRAL_H_
#define _CENTRAL_H_

/*
 * INCLUDE FILES
 ****************************************************************************************
 */
#include "user_config.h"

#if(ROPE_CENTRAL_SUP_ENABLE)

#include "prf_types.h"
#include "prf.h"
#include "central_task.h"
#include "attm.h"

/*
 * DEFINES
 ****************************************************************************************
 */
///Maximum number of USER task instances
#define CENTRAL_SENSOR_IDX_MAX     0x01

///CENTRAL Configuration Flag Masks
#define CENTRAL_MANDATORY_MASK              (0xFFFF)


#define CENTRAL_PRIMARY_SVC_UUID            0xFFC0
#define CENTRAL_SVC_WRITE_CHAR_UUID         0xFFC1
#define CENTRAL_SVC_INDICATE_CHAR_UUID      0xFFC2


/*
 * MACROS
 ****************************************************************************************
 */

#define CENTRAL_IS_SUPPORTED(mask) \
    (((central_env->prfl_cfg & mask) == mask))

/// Possible states of the BLPS task
enum
{
    /// Idle state
    CENTRAL_IDLE,
    /// Busy state
    CENTRAL_BUSY,

    /// Number of defined states.
    CENTRAL_STATE_MAX
};


///Attributes State Machine
enum
{
	CENTRAL_IDX_SVC = 0,

	CENTRAL_IDX_WRITE_CHAR,
	CENTRAL_IDX_WRITE_VAL,

	CENTRAL_IDX_IND_CHAR,
	CENTRAL_IDX_IND_VAL,
	CENTRAL_IDX_IND_CFG,

    CENTRAL_IDX_NB,
};

/*
 * TYPE DEFINITIONS
 ****************************************************************************************
 */

/// CENTRAL Profile Sensor environment variable
struct central_env_tag
{
    /// profile environment
    prf_env_t prf_env;
    /// CENTRAL Service Start Handle
    uint16_t start_hdl;
    /// Feature Configuration Flags
    uint16_t features;
    /// Profile configuration flags
    uint8_t prfl_cfg;
    /// Event (notification/indication) config
    uint8_t evt_cfg;
    /// Environment variable pointer for each connections
    uint8_t ind_cfg[BLE_CONNECTION_MAX];
    /// State of different task instances
    ke_state_t state[CENTRAL_SENSOR_IDX_MAX];
};


/*
 * GLOBAL VARIABLE DECLARATIONS
 ****************************************************************************************
 */

/*
 * FUNCTION DECLARATIONS
 ****************************************************************************************
 */

const struct prf_task_cbs* central_prf_itf_get(void);
extern void central_indicate_data(struct central_ind_upd_req const *param);

/*
 * TASK DESCRIPTOR DECLARATIONS
 ****************************************************************************************
 */
extern const struct ke_state_handler central_default_handler;

#endif 	//#if(ROPE_CENTRAL_SUP_ENABLE)

/// @} CENTRAL

#endif /* _CENTRAL_H_ */
